﻿using Loki.Commands;
using Loki.Engine;

namespace Loki.Utils
{
    /// <summary>
    /// Loki services helper class.
    /// </summary>
    public static class LokiServices
    {
        private const string LOKI_CONTEXT_NAME = "Loki";

        private const string LOKI_CONTEXT_SOURCE = "assembly://Loki.Core/Loki.Config/services.xml";

        private static IObjectContext _Context = new SpringContext(LOKI_CONTEXT_NAME, LOKI_CONTEXT_SOURCE);

        /// <summary>
        /// Loads the additional spring context.
        /// </summary>
        /// <param name="P_ObjectDefinition">The object definition.</param>
        public static void LoadContext(string P_ObjectDefinition)
        {
            _Context.LoadContext(P_ObjectDefinition);
        }

        /// <summary>
        /// Gets the logger service.
        /// </summary>
        /// <value>The configured logger service.</value>
        public static ILogService Logger
        {
            get
            {
                return _Context.GetObject<ILogService>(typeof(ILogService).Name);
            }
        }

        /// <summary>
        /// Gets the command service.
        /// </summary>
        /// <value>The configured command service.</value>
        public static ICommandService Command
        {
            get
            {
                return _Context.GetObject<ICommandService>(typeof(ICommandService).Name);
            }
        }

        /// <summary>
        /// Gets the event service.
        /// </summary>
        public static IEventService Event
        {
            get
            {
                return _Context.GetObject<IEventService>(typeof(IEventService).Name);
            }
        }

        /// <summary>
        /// Gets the task service.
        /// </summary>
        public static ITaskService Task
        {
            get
            {
                return _Context.GetObject<ITaskService>(typeof(ITaskService).Name);
            }
        }

        /// <summary>
        /// Gets the error service.
        /// </summary>
        public static IErrorService Errors
        {
            get
            {
                return _Context.GetObject<IErrorService>(typeof(IErrorService).Name);
            }
        }
    }
}
